package com.example.hssmgs.Student;

import com.example.hssmgs.R;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class show_info extends AppCompatActivity {

    RecyclerView recyclerView;
    List<Map<String,Object>> mydata;
    private Intent intent_2;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_info);


        intent_2 = getIntent();
        String student_account = intent_2.getStringExtra("student_id1");

        tv=findViewById(R.id.textViewtt);
        tv.setText(student_account);

//        mydata=getData(student_account);
//        recyclerView=findViewById(R.id.recyclerview);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.setAdapter(new MyAdapter());


    }

    //提供数据的函数
    private List<Map<String, Object>> getData(String student_account) {
        // 获取用户信息

        String test = "111";
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "学号");
        map.put("info", student_account);
        map.put("img", R.drawable.i1);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "数学");
        map.put("info", test);
        map.put("img", R.drawable.i2);
        list.add(map);
//        map = new HashMap<String, Object>();
//        map.put("title", "英语");
//        map.put("info", "2022-09-14");
//        map.put("img", R.drawable.i3);
//        list.add(map);

        return list;
    }

    class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{

        @NonNull
        @Override
        public MyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.item,parent,false);
            ViewHolder viewHolder=new ViewHolder(view);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull MyAdapter.ViewHolder holder, int position) {
            holder.title.setText((CharSequence)mydata.get(position).get("title"));
            holder.info.setText((CharSequence)mydata.get(position).get("info"));
            holder.img.setBackgroundResource((Integer)mydata.get(position).get("img"));
        }

        @Override
        public int getItemCount() {
            return mydata.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder{
            TextView title,info;
            ImageView img;
            public ViewHolder(@NonNull View itemView) {
                super(itemView);
                title=itemView.findViewById(R.id.title);
                info=itemView.findViewById(R.id.info);
                img=itemView.findViewById(R.id.img);
            }
        }

    }

}

